// src/stores/useNotifyStore.ts
import { defineStore } from 'pinia'
import userApi from '../api/mockData/user'

export const useNotifyStore = defineStore('notify', {
    state: () => ({
        notifications: [] as { type: 'success' | 'warning' | 'error' | 'info', title: string, content: string }[]
    }),
    actions: {
        async loadMockNotifications(role: 'member' | 'admin') {
            // 获取当前用户信息
            const userInfo = userApi.getUserInfo().data

            if (role === 'member') {
                this.notifications = [
                    {
                        type: 'success',
                        title: '欢迎回来',
                        content: `尊敬的成员 ${userInfo.username}，您已成功登录系统！`
                    },
                    {
                        type: 'info',
                        title: '系统提示',
                        content: '您可以开始预约您需要的服务。'
                    }
                ]
            } else if (role === 'admin') {
                // 获取用户列表数据
                const userList = await userApi.getUserList()
                const pendingCount = userList.data.records.length // 示例：使用用户数量作为待处理事项

                this.notifications = [
                    {
                        type: 'info',
                        title: '欢迎回来',
                        content: `尊敬的管理员 ${userInfo.username}，您有 ${pendingCount} 条待处理事项。`
                    },
                    {
                        type: 'warning',
                        title: '系统提醒',
                        content: '请及时处理今日的审核任务。'
                    }
                ]
            }
        }
    }
})